package com.addbrick.websocket.service.impl;

import com.addbrick.common.core.web.pojo.AjaxResult;
import com.addbrick.common.security.utils.SecurityUtils;
import com.addbrick.websocket.mapper.WSMessageMapper;
import com.addbrick.websocket.pojo.vo.SendMsgVO;
import com.addbrick.websocket.service.WSMessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * websocket消息 实现类
 * @author shiliuyinzhen
 */
@Service
public class WSMessageServiceImpl implements WSMessageService {

    @Resource
    private WSMessageMapper wsMessageMapper;

    /**
     * 查询所有消息记录
     * @param sendMsgVO
     * @return
     */
    @Override
    public List<SendMsgVO> getWSMessageList(SendMsgVO sendMsgVO) {
        Long userId = SecurityUtils.getUserId();
        List<SendMsgVO> list = wsMessageMapper.getWSMessageList(userId, sendMsgVO);
        return list;
    }

    /**
     * 批量确认消息
     * @param messageIds
     * @return
     */
    @Override
    public AjaxResult batchConfirmWSMessage(String[] messageIds) {
        Long userId = SecurityUtils.getUserId();
        return wsMessageMapper.batchConfirmWSMessage(userId, messageIds) > 0 ?
                AjaxResult.success("消息确认成功") : AjaxResult.error("消息确认失败");
    }
}
